package business.inhospitalqc;

import com.alibaba.fastjson.JSONObject;
import com.esotericsoftware.yamlbeans.YamlException;
import common.Data;
import common.RunCaseJson;
import common.Yaml;
import io.restassured.RestAssured;
import io.restassured.response.Response;
import org.apache.commons.configuration.ConfigurationException;
import org.apache.log4j.Logger;
import utils.GetFileMess;
import utils.YamlReadUtil;

import java.io.FileNotFoundException;

import static common.Login.login;
import static common.TestStep.requestAndRespondBody;


public class Tasklist {
    Logger log = Logger.getLogger(Tasklist.class);
    public static final String system = "env.properties";
    Data data = login();

/*
* 
* @Description:  获取住院质控待处理列表
 * @param i	  api-sourcedata/qc/task/list.json的datas
 * @param makeFlag	填写标志：0=未填写，1=已填
 * @param patientStatus	 --2是待填写，3是待审核，5待修改
* @return java.lang.String
* @author gujinle
* @date 2021-09-07 18:00
*/
    public   String getTasklist(int i,String makeFlag,String checkFlag,String patientStatus) throws FileNotFoundException, ConfigurationException, YamlException {
        String path=new GetFileMess().getValue("ymlPath",system);
        Yaml yaml= YamlReadUtil.getLocatorMap(path,this.getClass().getName());
        JSONObject json = new JSONObject();
        json.put("access_token", data.getAccessToken());
        json.put("authToken", data.getAccessToken());
        json.put("uniqu_no", data.getUniquNo());
        json.put("operatorId", data.getUserId());
        json.put("authUserId", data.getUserId());
        json.put("authName", data.getUserName());
        json.put("diseaseCode", yaml.getDatas().get(i).get("diseaseCode"));
        json.put("practitionerId", data.getUserId());   //从api-users/user/list获取userId
        json.put("type", yaml.getDatas().get(i).get("type"));   //1=copd，2=aecopd，3=指标检测图
        json.put("size",yaml.getDatas().get(i).get("size") );
        json.put("page", yaml.getDatas().get(i).get("page"));
        json.put("makeFlag", makeFlag);   //填写标志：0=未填写，1=已填
        json.put("checkFlag", checkFlag);  //审核标志：0=未审核，1=已审核
        json.put("isOption", yaml.getDatas().get(i).get("isOption"));

        json.put("patientStatus", patientStatus);
        log.info("请求参数：" + json.toString());
        Response response = RunCaseJson.runCase(json, "get", yaml.getUri());
        String jsonStr = response.asString();

        String url = RestAssured.baseURI + ":" + RestAssured.port + RestAssured.basePath +  yaml.getUri();
        requestAndRespondBody(url,json,jsonStr);  //写进allure报告

        log.info("响应报文：" + jsonStr);
        return jsonStr;
    }

    public static void main(String[] args) throws FileNotFoundException, ConfigurationException, YamlException {
        Tasklist tl=new Tasklist();
        tl.getTasklist(0,"0","0","2");
    }
}
